window.workspace = function(){
	var response  = <?#$respons?>;
	var swfVersionStr = "11.1.0";
	var xiSwfUrlStr = "";
	var params = {quality:"high", allowscriptaccess:"always", allowfullscreen:"true",wmode:"opaque"};
	var attributes = "";
	var win, form, store, grid, pwin, sm;
	var sid = {'userid':Ext.id(), 'play':Ext.id(), 'lttime':Ext.id(), 'status':Ext.id(),
		'gttime':Ext.id(), 'sdate':Ext.id(), 'edate':Ext.id(), 'ischeck':Ext.id(), 'tagid':Ext.id()};
	//双击播放选中的
	function doPlay(data) {
		if(!pwin) {
			pwin = new Ext.Window({
				title	  : '编辑直播时长[Edit]',
				iconCls	  : 'icon-edit',	
				width	  : 640,
				height	  : 480,
				items	  : [{html:'<div id="'+sid.play+'"></div>'}],
				listeners : {'afterrender':function(){
					var flashvars = {"file":data.get('hls')};
					swfobject.embedSWF("/static/flash/vodplayer/vodplayermodular.swf", sid.play,
							"640", "480", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
				}},
				closeAction : 'hide'
			});
		}
		pwin.show();
	};
	//审核通过
	function doCheck(status) {
		var rcs = grid.sm.getSelections();
		if(Ext.isEmpty(rcs)) {
			Ext.Msg.alert(GLang['30003'], GLang['30020']);
			return;
		}
		var ids= [];
		Ext.each(rcs, function(item){
			ids.push(item.get('id'));
		});
		Ext.Msg.prompt(GLang['30029'], GLang['30028'], function(btn, memo){
			if(btn=="ok") {
				var remark = String(memo).trim();
		    	Ext.Ajax.request({
					url		: '/admin/live/basic/event/docheck.html',
					params	: {'ids':ids.join(','), 'status':status, 'notes':remark},
					success : function(resp, req) {
						var data = Ext.decode(resp.responseText);
						if(data.code == 0) {
							store.reload(); 
						} else {
							Ext.Msg.alert(GLang['30003'], data.msg);
						}
					}
				});
			}
			
		}, null, true);
	}
	
	//初始化设置参数
	function doArgs() {
		var args = {};
		args.userid = Ext.getCmp(sid.userid).getValue();
		args.gttime = Ext.getCmp(sid.gttime).getValue();
		args.lttime = Ext.getCmp(sid.lttime).getValue();
		args.sdate  = Ext.getCmp(sid.sdate).getValue();
		args.edate  = Ext.getCmp(sid.edate).getValue();
		args.tagid  = Ext.getCmp(sid.tagid).getValue();
		args.status = Ext.getCmp(sid.status).getValue();
		args.ischeck= Ext.getCmp(sid.ischeck).getValue();
		return args;
	};
	//编辑无效时长
	function doSetTime() {
		var data = grid.sm.getSelected();
		if(Ext.isEmpty(data)) {
			Ext.Msg.alert(GLang['30003'], GLang['30020']);
			return;
		}
		if(!win) {
		    form = new Ext.form.FormPanel({
				frame		: true,
				border		: false,
				bodyStyle	: 'padding:8px;',
		        labelWidth	: 140,
		        labelAlign  : 'right',
		    	defaults	: {
		    		xtype	  : 'textfield'
		    	},
		    	items		: [{
					xtype		: 'hidden',
					name		: 'id',
					value		: 0
				},{
					fieldLabel	: '主播[Anchor]',
					width		: 240,
					name		: 'user',
					disabled    : true
				},{
					xtype		: 'textfield',
					fieldLabel	: '直播间标题[Title]',
					name		: 'title',
					width		: 240,
					disabled    : true
				},{
					xtype		: 'textfield',
			 		fieldLabel	: '直播时长/s[LiveTime]',
					name		: 'longtime',
					width		: 160,
					disabled    : true
				},{
		    		xtype		: 'combo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.status)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '状态[Status]',
		            width			: 160,
		            allowBlank		: false,
					triggerAction	: 'all',
					hiddenName		: 'status',
		            name			: 'status'
		        },{
					xtype		: 'numberfield',
			 		fieldLabel	: '无效时长/s[InvalidTime]',
					name		: 'wastetime',
					width		: 160,
					allowBlank	: false
				},{
					xtype		: 'textarea',
					fieldLabel	: '审核备注[Notes]',
					width		: 300,
					name		: 'remarks',
					allowBlank	: false
				}]
			});
			win = new Ext.Window({
				title	: '编辑直播时长[Edit]',
				iconCls	: 'icon-edit',	
				width	: 520,
				items	: [form],
				closeAction : 'hide',
				bbar 	: {
					xtype		: 'toolbar',
					buttonAlign	: 'right',
					items		: [{
						text	: '保存[Save]', 
						iconCls	: 'icon-save',
						url     : '/admin/live/basic/event/dosave.html',
						handler	: function(){
						if(!form.getForm().isValid())
		        			return;
		        		form.getForm().submit({
		        			waitMsg		: GLang['30017'],
							waitTitle 	: GLang['30003'],
			        		clientValidation: true,
			        		url		: '/admin/live/basic/event/dosave.html',
				        	success	: function(form, action) {
				        		store.reload();
				        		win.hide();
							},
							failure	: main.submitFailure
				    	});
					}}]
				}
			});
		}
		win.show();
		form.getForm().loadRecord(data);
	};
	store = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/live/basic/event/dolist.html',
	    remoteSort	: true,
	    sortInfo	: {
            field		: 'id',
            direction	: 'DESC'
		},
		baseParams	: {
			userid  : response.userid,
			sdate   : response.sdate,
			edate   : response.edate,
			status  : response.lstatus,
			start	: 0,
			limit	: main.pageSize
		},
		autoLoad		: true,
	    root			: 'dataset',
	 	totalProperty	: 'total',
	    fields			: ['id', 'userid', 'title', 'user', 'tagid', 'tag', 'agent', 'tools', 'notes',
	        'link', 'profile', 'offtime', 'livetime', 'validtime', 'invalidtime', 'starlv', 'status',
	        'lasttime', 'lformat', 'aritime', 'ischeck', 'operator', 'chktime', 'rtmp', 'longtime', 'across']
	});
	sm   = new Ext.grid.CheckboxSelectionModel();
	grid = {
		xtype		: 'grid',
		title		: response.title,
		region		: 'center',
	    store		: store,
	    columns		: [
	        sm,
	    	{header: '直播场次[ID]', width:50, sortable:true, dataIndex:'id'},
			{header: '主播[Anchor]', width:70, sortable:true, dataIndex:'userid', renderer:function(v,meta,obj) {
				if (!obj.get('profile')) {
					return obj.get('user');
				}
				var anchor = obj.get('user')+'['+v+']';
				return '<a href="'+obj.get('profile')+'" target="__blank">'+anchor+'</a>';
			}},
			{header: '标题[Title]', width:100, dataIndex:'title', renderer:function(v,meta,obj) {
				return '<a href="'+obj.get('link')+'" target="__blank">'+v+'</a>';
			}},
			{header: '分类[Tag]', width:60, sortable:true, dataIndex:'tagid', renderer:function(v, meta, obj){
				return obj.get('tag');
			}},
			{header: '开播时间[StartTime]', width:80, sortable:true, dataIndex:'aritime'},
			{header: '心跳时间[NotifyTime]', width:80, sortable:true, dataIndex:'lasttime'},
			{header: '结束时间[EndTime]', width:80, sortable:true, dataIndex:'offtime'},
			{header: '直播时长[LiveTime]', width:80, dataIndex:'livetime'},
			{header: '有效时间[ValidTime]', width:80, dataIndex:'validtime'},
			{header: '无效时间[InvalidTime]', width:80, dataIndex:'invalidtime'},
			{header: '主播等级[StarLv]', width:60, dataIndex:'starlv'},
			{header: '推流地址[Rtmp]', width:120, dataIndex:'rtmp'},
			{header: '状态[Status]', width:60, sortable:true, dataIndex:'status', renderer:function(v){
				return response.status[v];
			}},
			{header: '横竖屏[Across]', width:60, sortable:true, dataIndex:'across', renderer:function(v,meta,obj){
				if(Ext.isNumber(v)) {
					return response.across[v]+'['+obj.get('tools')+']';
				}
				return '';
			}},
			{header: '审核状态[IsCheck]', width:60, sortable:true, dataIndex:'ischeck', renderer:function(v){
				return response.ischeck[v];
			}},
			{header: '审核者[Operator]', width:60, dataIndex:'operator'},
			{header: '审核时间[CheckTime]', width:100, dataIndex:'chktime'},
		],
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
	    listeners	: {
			'destroy':function(){
    			win && win.close();
    		},'rowdblclick':function(grid, index, e){
		    	var data = grid.store.getAt(index).copy();
		    	doPlay(data);
		    },'render':function(obj){
				main.gridRender(obj, ['notes']);
	    	}
		},
	    sm			: sm,
	    stripeRows	: true,
	    tbar		: [{
			text	: '刷新',
			iconCls	: 'icon-refresh',
			handler : function(){
				store.reload(); 
			}
	    },'-',{
			text	: '审核通过',
			iconCls	: 'icon-edit',
			url		: '/admin/live/basic/event/docheck.html',
			handler : function() {
				doCheck(1);
			}
		},'-',{
			text	: '设置无效',
			iconCls	: 'icon-edit',
			url		: '/admin/live/basic/event/docheck.html',
			handler : function() {
				doCheck(0);
			}
		},'-',{
			text	: '时长编辑',
			iconCls	: 'icon-edit',
			url		: '/admin/live/basic/event/dosave.html',
			handler : function() {
				doSetTime();
			}
		},'-', '主播:',{
			xtype		: 'combo',
			store		: new Ext.data.JsonStore({
				url	: '/admin/live/share/douser.json',
				autoDestroy: true,
				fields: ['id', 'name'],
				root: 'dataset'
			}),
			listeners		: {
				afterrender : function(obj) {
					obj.setRawValue(response.user);
				}
			},
			value			: response.userid,
			id	    	    : sid.userid,
			displayField	: 'name',
			valueField		: 'id',
			emptyText		: 'Selected...',
			minChars		: 1,
			 pageSize		: 10,
			listWidth		: 258,
			width			: 160,
			typeAhead		: true,
			typeAheadDelay  : 0,
			triggerAction	: 'all',
			enableKeyEvents : true,
			mode			: 'remote'
		},'结束时间:',{
			xtype       : 'datetimefield',
			id  		: sid.sdate,
			value		: response.sdate,
			width	    : 140
		},'<->',{
			xtype       : 'datetimefield',
			id  		: sid.edate,
			value		: response.edate,
			width	    : 140
		},'时长/s:',{
			xtype       : 'numberfield',
			id  		: sid.gttime,
			width	    : 50
		},'<->',{
			xtype       : 'numberfield',
			id  		: sid.lttime,
			width	    : 50
		},'状态:',{
			xtype		: 'combo',
			store		: new Ext.data.ArrayStore({
		        fields: ['id','name'],
		        data: main.cv2Array(response.status)
		    }),
			displayField	: 'name',
			valueField		: 'id',
			mode			: 'local',
			triggerAction	: 'all',
			value           : response.lstatus,
			emptyText		: 'selected...',
			width			: 80,
			id  			: sid.status
		},'是否审核:',{
			xtype		: 'combo',
			store		: new Ext.data.ArrayStore({
		        fields: ['id','name'],
		        data: main.cv2Array(response.ischeck)
		    }),
			displayField	: 'name',
			valueField		: 'id',
			mode			: 'local',
			triggerAction	: 'all',
			emptyText		: 'selected...',
			width			: 80,
			id  			: sid.ischeck
		},'标签分类',{
			xtype		: 'combo',
			store		: new Ext.data.JsonStore({
				url	: '/admin/live/share/dotags.html',
				autoDestroy: true,
				fields: ['id', 'name'],
				root: 'dataset'
			}),
			id  			: sid.tagid,
			displayField	: 'name',
			valueField		: 'id',
			emptyText		: 'selected...',
			minChars		: 1,
			 pageSize		: 10,
            listWidth		: 258,
            width	    	: 100,
			typeAhead		: true,
			typeAheadDelay  : 0,
			triggerAction	: 'all',
			enableKeyEvents : true,
			mode			: 'remote'
		},'-',{
			text			: '检索',
			iconCls			: 'icon-search',
			handler: function() {
				store.baseParams = doArgs();
				store.reload(); 
			}
		},'-',{
			text			: '导出',
			iconCls			: 'icon-excel',
			url             : '/admin/live/basic/event/doexport',
			handler: function() {
				var query  = Ext.urlEncode(doArgs());
				window.open('/admin/live/basic/event/doexport?'+query);
			}
		}],
		bbar		: new Ext.PagingToolbar({
			pageSize	: main.pageSize,
			store		: store,
			displayInfo	: true
		})
	};
	return grid;
}();